package com.cosmosource.core.advice;

import com.cosmosource.core.common.DateConst;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @author cosmo
 * @date
 */
public class BaseExceptionAdvice {

    Map<String, Object> buildResponseBody(String error, HttpServletRequest request) {
        Map<String, Object> body = new LinkedHashMap<>();
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(DateConst.DATE_TIME);
        body.put("timestamp", LocalDateTime.now().format(dateTimeFormatter));
        body.put("path", request.getRequestURI());
        body.put("method", request.getMethod());
        body.put("info", error);
        return body;
    }
}
